
// 团购-商品列表页
function tuan_products() {
    let mockData = Mock.mock({
        "logobanner": "@image(1920x115,@color)",
        "navlist|8": [{
            "text": "@ctitle(2,4)",
            "href": "#"
        }]
    });
    new Vue({
        el: '#ms_products',
        data() {
            return {
                prolist: null,
                timeleft: null, //剩余秒数
                time: null, //剩余秒数转换后存储的对象
                activityProductList:null,
                activityState:null,
                shopInfo:{},//店铺信息
                logobanner:null,
                navlist:null,
            }
        },
        components: {
            'pro-list': tuan_pro_list
        },
        methods: {
            getData() {
                var that = this;
                var href = urlParam.href();

                this.navlist = mockData.navlist;
                axios({
                    method: 'post',
                    url: urlParam.domain() + '/api/shop/shopInfo?id=' + href.businessId,
                    responseType: 'stream',
                }).then(function(response) {
                    that.logobanner = response.data.data.backgroundImg;
                    that.shopInfo = response.data.data;
                });
                //获取团购活动商品列表及活动时间
                axios({
                    method: 'post',
                    url: urlParam.domain() + '/api/groupPurchasingActivity/activityProductList?activityId=' + href.activityId,
                    responseType: 'stream',
                }).then(function(response) {
                    let d = response.data.data;
                    that.activityProductList = d.activityList;
                    if(d.startTime>0){
                        //未开始状态
                        that.timeleft = d.startTime;
                        that.activityState = "距团购开始还剩余";
                    }else{
                        if(d.startTime<=0 && d.endTime >=0){
                            //秒杀进行中
                            that.timeleft = d.endTime;
                            that.activityState = "距团购结束还剩余";
                        }else{
                            //秒杀已结束
                            that.activityState = "团购活动已结束";
                        }
                    }
                });
            },
            //将剩余秒数转换为天 时 分 秒格式
            exchangeTimeLeave: function() {
                this.time = transformTimeleft(this.timeleft);
            },
            //倒计时
            countdown: function() {
                var that = this;
                setInterval(function() {
                    that.timeleft--;
                    that.exchangeTimeLeave();
                }, 1000)
            }
        },
        created() {
            this.getData();
            this.exchangeTimeLeave();
            this.countdown();
        }
    })
}

// 团购-商品列表页-单项
let tuan_pro_item = {
    template: `<div class="ms-pro-item-wrap">
        <a :href="pro.pcHref">
        <img :src="pro.commodityPicImg">
        <div class="ms-pro-detail-wrap">
            <div>
                <span class="unit">￥</span>
                <span class="price">{{pro.activityPrice}}</span>
            </div>
            <div class="sell-info">
                <del>￥{{pro.commodityPrice}}</del>
                <p>{{pro.salesNumber}}件已付款</p></div>
            <div class="qiang">团</div>
            <div class="triangle-left"></div>
            <p class="ms-pro-title">{{pro.title}}</p>
        </div>
        </a>
    </div>`,
    props: ['pro'],
    data() {
        return {
            hour: null,
            minute: null,
            second: null
        }
    }
}

// 团购-商品列表
let tuan_pro_list = {
    template: `<div class="ms-pro-list">
        <pro-item v-for="(pro,index) in prolist" :key="index" :pro="pro"></pro-item>
    </div>`,
    props: ['prolist'],
    components: {
        'pro-item': tuan_pro_item
    }
}